package com.ubing.boot.notesforjava.listener;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @ClassName : MyApplicationListener
 * @Description : MyApplicationListener
 * @Author : ubing
 * @Date: 2023-06-14 14:52
 */
@Component
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) // 配置为非单例模式
public class MyApplicationListener implements ApplicationListener<MyListener> {
    // 测试spring容器单例
    private Integer a=0;
    @Override
    public void onApplicationEvent(MyListener event) {
        this.a++;
        System.out.println("custom event: " + event.getSource()+this.a);
    }
}